package breeze.framework.utils;

import java.util.regex.Pattern;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

public class HutoolUtils {

	//密钥对生成 http://web.chacuo.net/netrsakeypair
	private static String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAN5AynJqM+DjWNQ/dOaxKWOok1MMLMt4i9t9VcwkPCOQYRzf3/58ocP26muEqdDl50bQqWoOdbJVWm08fDus4Vq4JuSEe+6o54Alx/DEls2NOTbRk8y+s0G7xM/pqJXzBZrJfs7Xy3b9bXv/A/89sQ7BGiKZXOc2JGknkHtwYJUZAgMBAAECgYBrtpbnEJWH/mcEpqRvUZkvlXmhHBtxmUCe5YV5ZG5JBiYqqk2StrBnmvlNloP+nA2Ugng40D02aqtimZfUDBtCxozSHDo4EAWYKc/Ja0C9hFiBAn3jZCo0e7SWysY29CbooH4aaV/jEiPO+wk1A3CxI35pf+pgxut3hf/83NXPIQJBAP+z+oMujaX9OmVTe1ipNy3zsiUPzqI7xktfTo0nTVcsqL2tafhIsLffAjlKm0ZYn3WkRV20H2hZWhSsPIizUtUCQQDegt4RYyNylJPfoZWe6fyIAaBgPsI1kZM3c9DWaWFJDomw2PaNgay80g6uXW0Vt7sa6TGqmO3WG+3GPtUiwDM1AkBIgClphIuZIuGp1S/GBcSlfNFn/MFj8nrY6B8HmrstGnaFwWOoiEPC/rJMuECqg3pDCt64INg+6AbIkcVgJSg5AkAEwpPxl0dY2ijXreM/hQ3r8uz1YiJRdw3JL+cVzydPosn7SIjtugpx96Rswn7k6gtMphRz69WasPpDNXDlz2rJAkEA6IFPmJFBDwM5L1s5CNHch+z4EtKvD7vy8vPEwZGJ2isvF7NrlULTBSAXG11UAvFVK9O7hDv9bdYUqCgmQNIxbA==";
	private static String publicKey =  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDeQMpyajPg41jUP3TmsSljqJNTDCzLeIvbfVXMJDwjkGEc39/+fKHD9uprhKnQ5edG0KlqDnWyVVptPHw7rOFauCbkhHvuqOeAJcfwxJbNjTk20ZPMvrNBu8TP6aiV8wWayX7O18t2/W17/wP/PbEOwRoimVznNiRpJ5B7cGCVGQIDAQAB";
	private static RSA rsa = new RSA(privateKey,publicKey);
	//private static String passwordRegex = "^(?![a-zA-Z]+$)(?![a-z\\d]+$)(?![a-z!@#\\$%]+$)(?![A-Z\\d]+$)(?![A-Z!@#\\$%]+$)(?![\\d!@#\\$%]+$)[a-zA-Z\\d!@#\\$%]{8,}+$";

	/**
	 * 将加密后的base64串解密成明文字符串
	 * 与前端jsencrypt.js的decrypt方法效果相同
	 */
	public static String decrypt(String base64_str) {
		return rsa.decryptStr(base64_str, KeyType.PrivateKey);
	}
	
	/**
	 * 将明文字符串加密成base64串
	 * 与前端jsencrypt.js的encrypt方法效果相同
	 */
	/*public static String encrypt(String str) {
		return rsa.encryptBase64(str.getBytes(), KeyType.PublicKey);
	}
	
	public static boolean isValidPassword(String password) {
		Pattern p = Pattern.compile(passwordRegex);
        return p.matcher(password).matches();
	}*/
	
	public static void main(String[] args) {
		System.out.println(decrypt("aJH++n3S8S6dIJOQOb1z8TY94BIM3c9YJJEMF3yiNxK8wUHNynvLyEVD3tEODl1cIHNoy8Z8ZyATZ8GkYkkyKBLKylDRbL8Lpipidm8ibUz4RF1Xh1WlEC5Ze3gwLYkiCsdaXAYYkpLEeJP/t3nmozZHJgFYnNMEWaZK2xGppAc="));
	}
}
